<template>
  <div class="row">
    <div v-for="column in comlumnList" :key="column._id" class="col-4 mb-4">
      <div class="card h-100 shadow-sm" >
        <!-- style="width: 18rem;" -->
        <div class="card-body text-center">
          <img :src="column.avatar && column.avatar.url" class="rounded-circle border border-light my-3" :alt="column.title">
          <h5 class="card-title">{{column.title}}</h5>
          <p class="card-text text-start">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
          <!-- <router-link :to="{name: 'column', params: {id: column.id}}" class="btn btn-outline-primary">前往专栏</router-link> -->
          <router-link :to="`/column/${column._id}`" class="btn btn-outline-primary">前往专栏</router-link>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, PropType, computed } from 'vue'
import { ColumnProps } from '../store'

export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProps[]>,
      required: true
    }
  },
  setup (props, context) {
    const comlumnList = computed(() => {
      return props.list.map(column => {
        if (!column.avatar) {
          column.avatar = {
            url: require('@/assets/avatar.jpg')
          }
        } else {
          column.avatar.url = column.avatar.url + '?x-oss-process=image/resize,pad,w_50,h_50'
        }
        return column
      })
    })
    return {
      comlumnList
    }
  }
})
</script>

<style lang="less" scoped>
div {
  overflow: hidden;
}
.card-body img {
  width: 50px;
  height: 50px;
}
</style>
